package com.lmh.utils;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @program code
 * @Description
 * @Author limeihua
 * @Date 2024/07/22 16:11
 * @Version 1.0
 */
public class ThreadPool {

    private ThreadPool(){

    }
    private static volatile ThreadPoolExecutor threadPoolExecutor;
    private static final LinkedBlockingQueue<Runnable> queue =  new LinkedBlockingQueue<>();

    public static ThreadPoolExecutor getThreadPoolExecutor() {
        if(threadPoolExecutor == null){
            synchronized (ThreadPool.class){
                if(threadPoolExecutor == null){
                    threadPoolExecutor = new ThreadPoolExecutor(
                            5,
                            20,
                            5,
                            TimeUnit.MINUTES,
                            queue
                            );
                }
            }
        }
        return threadPoolExecutor;
    }
}
